/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.excellent_student.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.excellent_student.entity.TbExcellentStudent;
import com.thinkgem.jeesite.modules.excellent_student.service.TbExcellentStudentService;

/**
 * 优秀在校生Controller
 * @author hang
 * @version 2017-01-15
 */
@Controller
@RequestMapping(value = "${adminPath}/excellent_student/tbExcellentStudent")
public class TbExcellentStudentController extends BaseController {

	@Autowired
	private TbExcellentStudentService tbExcellentStudentService;
	
	@ModelAttribute
	public TbExcellentStudent get(@RequestParam(required=false) String id) {
		TbExcellentStudent entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = tbExcellentStudentService.get(id);
		}
		if (entity == null){
			entity = new TbExcellentStudent();
		}
		return entity;
	}
	
	@RequiresPermissions("excellent_student:tbExcellentStudent:view")
	@RequestMapping(value = {"list", ""})
	public String list(TbExcellentStudent tbExcellentStudent, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<TbExcellentStudent> page = tbExcellentStudentService.findPage(new Page<TbExcellentStudent>(request, response), tbExcellentStudent); 
		model.addAttribute("page", page);
		return "modules/excellent_student/tbExcellentStudentList";
	}

	@RequiresPermissions("excellent_student:tbExcellentStudent:view")
	@RequestMapping(value = "form")
	public String form(TbExcellentStudent tbExcellentStudent, Model model) {
		model.addAttribute("tbExcellentStudent", tbExcellentStudent);
		return "modules/excellent_student/tbExcellentStudentForm";
	}

	@RequiresPermissions("excellent_student:tbExcellentStudent:edit")
	@RequestMapping(value = "save")
	public String save(TbExcellentStudent tbExcellentStudent, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, tbExcellentStudent)){
			return form(tbExcellentStudent, model);
		}
		tbExcellentStudentService.save(tbExcellentStudent);
		addMessage(redirectAttributes, "保存优秀在校生成功");
		return "redirect:"+Global.getAdminPath()+"/excellent_student/tbExcellentStudent/?repage";
	}
	
	@RequiresPermissions("excellent_student:tbExcellentStudent:edit")
	@RequestMapping(value = "delete")
	public String delete(TbExcellentStudent tbExcellentStudent, RedirectAttributes redirectAttributes) {
		tbExcellentStudentService.delete(tbExcellentStudent);
		addMessage(redirectAttributes, "删除优秀在校生成功");
		return "redirect:"+Global.getAdminPath()+"/excellent_student/tbExcellentStudent/?repage";
	}

}